import os

import yaml

# 定义一个全局变量来存储配置数据
CONFIG = None
IMAGE_PATH = None

def load_config_from_yaml(file_path):
    global CONFIG  # 声明我们正在引用全局变量CONFIG
    with open(file_path, 'r', encoding='utf-8') as file:
        CONFIG = yaml.safe_load(file)

def getConfigPath():
    # 获取当前文件的绝对路径
    current_file_path = os.path.abspath(__file__)
    # 获取当前文件所在的目录
    current_dir = os.path.dirname(current_file_path)
    # 获取当前文件的上一层目录
    parent_dir = os.path.dirname(current_dir)
    # 构建resources文件夹下的config.yml文件的路径
    resources_dir = os.path.join(parent_dir, 'resources')
    global IMAGE_PATH
    IMAGE_PATH = os.path.join(resources_dir, 'images')
    #print(IMAGE_PATH)
    return os.path.join(resources_dir, 'config.yml')


# 在程序开始时加载配置
load_config_from_yaml(getConfigPath())


if __name__ == '__main__':
    getConfigPath()
    #print(IMAGE_PATH)
